﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using Assist;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using YArchitech.Controls;
using YArchitech.LIB;
using YArchitech.LIB.YJKControls;
using YJKArchUtils.Utils;
using YJKRevitStairs.StairsModel.CommonUnit;
using YJKRevitStairs.StairsModel.DataInfos;
using YJKRevitStairs.StairsModel.Kit;

namespace YJKRevitStairs.StairsModel.Form
{
	public partial class SteelStairsForm : EscBaseForm
	{
		public SteelStairsForm(ExternalCommandData cmdData, List<string> listStairsTypeName, List<string> listBeamTypeName)
		{
			this.m_Revit = cmdData;
			this.m_StairsDrawingKit = new SteelStairsKit(this.m_Revit.Application.Application);
			this.m_slistStairsTypeName = this.GetStairsTypeName(listStairsTypeName);
			this.m_sListBeamTypeName = this.GetBeamTypeName(listBeamTypeName);
			this.m_listStairsData = new List<double>();
			this.InitializeComponent();
			this.m_MainPreviewer = new Previewer(this, this.pnlPreview.Left, this.pnlPreview.Top, this.pnlPreview.Width, this.pnlPreview.Height, 1u);
			this.pnlPreview.Visible = false;
			base.MouseWheel += this.m_MainPreviewer.MouseWheel;
		}

		public double StairsHeight
		{
			get
			{
				return Convert.ToDouble(this.hyTbStairsHeight.Text);
			}
			set
			{
				this.hyTbStairsHeight.Text = value.ToString("f2");
			}
		}

		public double StairsOffset
		{
			get
			{
				return YJKRevitStairs.StairsModel.CommonUnit.Common.StrToDouble(this.hyTbStairsOffset.Text, 0.0);
			}
			set
			{
				this.hyTbStairsOffset.Text = value.ToString("f2");
			}
		}

		public double StairsAngle
		{
			get
			{
				return Convert.ToDouble(this.cmbStairsAngle.Text) / 180.0 * Math.PI;
			}
			set
			{
				this.cmbStairsAngle.Text = (value * 180.0 / Math.PI).ToString("f1");
			}
		}

		public double StairsWidth
		{
			get
			{
				return Convert.ToDouble(this.cmbStairsWidth.Text);
			}
			set
			{
				this.cmbStairsWidth.Text = value.ToString("f2");
			}
		}

		public double StairsLength
		{
			get
			{
				return Convert.ToDouble(this.tbStairsLength.Text);
			}
			set
			{
				this.tbStairsLength.Text = value.ToString("f2");
			}
		}

		public int TreadCount
		{
			get
			{
				return Convert.ToInt32(this.tbTreadCount.Text);
			}
			set
			{
				this.tbTreadCount.Text = value.ToString("f0");
			}
		}

		public double TreadHeight
		{
			get
			{
				return Convert.ToDouble(this.hyTbTreadHeight.Text);
			}
			set
			{
				this.hyTbTreadHeight.Text = value.ToString("f2");
			}
		}

		public double TreadDepth
		{
			get
			{
				return Convert.ToDouble(this.tbTreadDepth.Text);
			}
			set
			{
				this.tbTreadDepth.Text = value.ToString("f2");
			}
		}

		public double BeamBottomOffsetV
		{
			get
			{
				return Convert.ToDouble(this.hyTbBeamBottomOffsetV.Text);
			}
			set
			{
				this.hyTbBeamBottomOffsetV.Text = value.ToString("f2");
			}
		}

		public double BeamTopOffsetV
		{
			get
			{
				return Convert.ToDouble(this.hyTbBeamTopOffsetV.Text);
			}
			set
			{
				this.hyTbBeamTopOffsetV.Text = value.ToString("f2");
			}
		}

		public double BeamTopOffsetH
		{
			get
			{
				return Convert.ToDouble(this.hyTbBeamTopOffsetH.Text);
			}
			set
			{
				this.hyTbBeamTopOffsetH.Text = value.ToString("f2");
			}
		}

		public double RotateAngle
		{
			get
			{
				return YJKRevitStairs.StairsModel.CommonUnit.Common.StrToDouble(this.hyTbRotateAngle.Text, 0.0) / 180.0 * Math.PI;
			}
			set
			{
				this.hyTbRotateAngle.Text = (value * 180.0 / Math.PI).ToString("f0");
			}
		}

		public double RailingHeight
		{
			get
			{
				return Convert.ToDouble(this.hyTbRailingHeight.Text);
			}
			set
			{
				this.hyTbRailingHeight.Text = value.ToString("f2");
			}
		}

		public XYZ BasePoint
		{
			get
			{
				return this.m_BasePoint;
			}
		}

		public SteelStairsForm.MeasureType theMeasureType
		{
			get
			{
				return this.m_MeasureType;
			}
		}

		public LineRunData GetRunData()
		{
			LineRunData lineRunData = new LineRunData();
			lineRunData.RunWidth = YJKRevitStairs.StairsModel.CommonUnit.Common.MMToFeet(this.StairsWidth);
			lineRunData.TreadHeight = YJKRevitStairs.StairsModel.CommonUnit.Common.MMToFeet(this.TreadHeight);
			if (this.m_bRightAngle)
			{
				lineRunData.TreadDepth = 0.0;
			}
			else
			{
				lineRunData.TreadDepth = YJKRevitStairs.StairsModel.CommonUnit.Common.MMToFeet(this.TreadDepth);
			}
			lineRunData.TreadCount = this.TreadCount;
			lineRunData.RunLength = lineRunData.TreadDepth * (double)lineRunData.TreadCount;
			lineRunData.BottomElevation = YJKRevitStairs.StairsModel.CommonUnit.Common.MMToFeet(this.m_dBottomElevation);
			return lineRunData;
		}

		public SteelStairsBeamData GetBeamData()
		{
			return new SteelStairsBeamData
			{
				m_bBottomBeam = this.chkBottomBeam.Checked,
				m_bTopBeam = this.chkTopBeam.Checked,
				m_dBottomOffsetV = YJKRevitStairs.StairsModel.CommonUnit.Common.MMToFeet(this.BeamBottomOffsetV),
				m_dTopOffsetV = YJKRevitStairs.StairsModel.CommonUnit.Common.MMToFeet(this.BeamTopOffsetV),
				m_dTopOffsetH = YJKRevitStairs.StairsModel.CommonUnit.Common.MMToFeet(this.BeamTopOffsetH),
				m_dElevation = 0.0
			};
		}

        public YJKRevitStairs.StairsModel.DataInfos.FloorType GetFloorType()
		{
			if (this.rbFirstFloor.Checked)
			{
                return YJKRevitStairs.StairsModel.DataInfos.FloorType.FT_Bottom;
			}
			if (this.rbMiddleFloor.Checked)
			{
                return YJKRevitStairs.StairsModel.DataInfos.FloorType.FT_Mid;
			}
            return YJKRevitStairs.StairsModel.DataInfos.FloorType.FT_Top;
		}

		public string GetFamilyName()
		{
			string result = "";
			string text = "斜钢梯 A 35.5~45";
			string text2 = "斜钢梯 A 59~73";
			double num = this.StairsAngle * 180.0 / Math.PI;
			string text3;
			if (90.0 <= num)
			{
				text3 = "90°直钢梯_不带平台";
			}
			else if (35.5 <= num && num <= 45.0)
			{
				text3 = text;
			}
			else
			{
				text3 = text2;
			}
			string text4 = this.cmbStairsType.Text;
			if (text4.Contains("A") || text4.Contains("直梯"))
			{
				result = text3;
			}
			else if (text4.Contains("B"))
			{
				result = text3.Replace('A', 'B');
			}
			else if (text4.Contains("C"))
			{
				result = text3.Replace('A', 'C');
			}
			else if (text4.Contains("D"))
			{
				result = text3.Replace('A', 'D');
			}
			return result;
		}

		public string GetBeamName()
		{
			return this.cmbBeamType.Text;
		}

		public bool IsRightAngle()
		{
			return this.m_bRightAngle;
		}

		public bool GetNoteInfo()
		{
			return this.chkNoteInfo.Checked;
		}

		public bool GetTBMirror()
		{
			return this.chkTBMirror.Checked;
		}

		public bool GetLRMirror()
		{
			return this.chkLRMirror.Checked;
		}

		public int GetInsertPointIndex()
		{
			return this.m_BasePointIndex;
		}

		public int GetInnerRail()
		{
			if (this.chkInnerRailing.Checked)
			{
				return 1;
			}
			return 0;
		}

		public int GetOuterRail()
		{
			if (this.chkOutRailing.Checked)
			{
				return 1;
			}
			return 0;
		}

		protected override void DefWndProc(ref Message m)
		{
			int msg = m.Msg;
			if (msg == 1125)
			{
				if (m.WParam.ToInt32() != 1)
				{
					return;
				}
				List<CurveInfo> curves = new List<CurveInfo>();
				List<TextNoteInfo> textNotes = new List<TextNoteInfo>();
				try
				{
					this.GetProfileCurves(ref curves, ref textNotes);
					this.m_MainPreviewer.Curves = curves;
					this.m_MainPreviewer.TextNotes = textNotes;
					return;
				}
				catch (Exception)
				{
					return;
				}
			}
			base.DefWndProc(ref m);
		}

		private void GetProfileCurves(ref List<CurveInfo> curvesInfoList, ref List<TextNoteInfo> textNoteInfoList)
		{
			SteelStairs steelStairs = new SteelStairs();
			steelStairs.m_dStairsHeight = YJKRevitStairs.StairsModel.CommonUnit.Common.MMToFeet(this.StairsHeight);
			steelStairs.m_dStairsWidth = YJKRevitStairs.StairsModel.CommonUnit.Common.MMToFeet(this.StairsWidth);
			if (this.m_bRightAngle)
			{
				steelStairs.m_dStairsLength = 0.0;
			}
			else
			{
				steelStairs.m_dStairsLength = YJKRevitStairs.StairsModel.CommonUnit.Common.MMToFeet(this.StairsLength);
			}
			steelStairs.m_dTreadHeight = YJKRevitStairs.StairsModel.CommonUnit.Common.MMToFeet(this.TreadHeight);
			steelStairs.m_bRightAngle = this.m_bRightAngle;
			steelStairs.m_dRotateAngle = this.RotateAngle;
			steelStairs.m_RunData = this.GetRunData();
			steelStairs.m_BeamData = this.GetBeamData();
			steelStairs.m_FloorType = this.GetFloorType();
			steelStairs.m_nInsertPointIndex = this.m_BasePointIndex;
			steelStairs.m_bNoteUpStairs = this.GetNoteInfo();
			this.m_StairsDrawingKit.SteelStairsProfileCurves(ref steelStairs, this.chkLRMirror.Checked, this.chkTBMirror.Checked, this.chkBottomBeam.Checked, this.chkTopBeam.Checked);
			foreach (SingleRunCurveInfo singleRunCurveInfo in steelStairs.m_listRunCurve)
			{
				curvesInfoList.AddRange(singleRunCurveInfo.RunBoundaryCurvesInfoList);
				curvesInfoList.AddRange(singleRunCurveInfo.RunRiserCurvesInfoList);
				curvesInfoList.AddRange(singleRunCurveInfo.RunPathCurvesInfoList);
			}
			curvesInfoList.AddRange(steelStairs.m_listOtherCurve);
			textNoteInfoList = steelStairs.m_listText;
		}

		private void ReadData()
		{
			string path = Path.GetTempPath() + "SteelStairsForm.dat";
			if (!File.Exists(path))
			{
				this.hyTbStairsHeight.Text = "4500.00";
				this.hyTbStairsOffset.Text = "0.00";
				this.cmbStairsAngle.SelectedIndex = 0;
				this.cmbStairsWidth.SelectedIndex = 0;
				this.tbStairsLength.Text = "1375.79";
				this.tbTreadCount.Text = "16";
				this.hyTbTreadHeight.Text = "260.23";
				this.tbTreadDepth.Text = "79.56";
				this.hyTbRailingHeight.Text = "1000.00";
				this.chkInnerRailing.Checked = true;
				this.chkOutRailing.Checked = true;
				this.chkBottomBeam.Checked = false;
				this.chkTopBeam.Checked = true;
				this.cmbBeamType.SelectedIndex = 0;
				this.hyTbBeamBottomOffsetV.Text = "0.00";
				this.hyTbBeamTopOffsetV.Text = "0.00";
				this.hyTbBeamTopOffsetH.Text = "0.00";
				this.rbFirstFloor.Checked = true;
				this.rbMiddleFloor.Checked = false;
				this.rbTopFloor.Checked = false;
				this.hyTbRotateAngle.Text = "0.00";
				this.chkTBMirror.Checked = false;
				this.chkLRMirror.Checked = false;
				this.chkNoteInfo.Checked = false;
				return;
			}
			FileStream fileStream = new FileStream(path, FileMode.Open);
			StreamReader streamReader = new StreamReader(fileStream);
			streamReader.BaseStream.Seek(0L, SeekOrigin.Begin);
			int index = Convert.ToInt32(streamReader.ReadLine());
			this.SetComboBoxSelectedIndex(this.cmbStairsType, index);
			this.hyTbStairsHeight.Text = Convert.ToDouble(streamReader.ReadLine()).ToString("f2");
			this.hyTbStairsOffset.Text = YJKRevitStairs.StairsModel.CommonUnit.Common.StrToDouble(streamReader.ReadLine(), 0.0).ToString("f2");
			this.cmbStairsAngle.Text = Convert.ToDouble(streamReader.ReadLine()).ToString("f1");
			this.cmbStairsWidth.Text = Convert.ToDouble(streamReader.ReadLine()).ToString("f2");
			this.tbStairsLength.Text = streamReader.ReadLine();
			this.tbTreadCount.Text = Convert.ToDouble(streamReader.ReadLine()).ToString("f0");
			this.hyTbTreadHeight.Text = Convert.ToDouble(streamReader.ReadLine()).ToString("f2");
			this.tbTreadDepth.Text = streamReader.ReadLine();
			this.chkInnerRailing.Checked = Convert.ToBoolean(streamReader.ReadLine());
			this.chkOutRailing.Checked = Convert.ToBoolean(streamReader.ReadLine());
			this.hyTbRailingHeight.Text = Convert.ToDouble(streamReader.ReadLine()).ToString("f2");
			this.chkBottomBeam.Checked = Convert.ToBoolean(streamReader.ReadLine());
			this.chkTopBeam.Checked = Convert.ToBoolean(streamReader.ReadLine());
			index = Convert.ToInt32(streamReader.ReadLine());
			this.SetComboBoxSelectedIndex(this.cmbBeamType, index);
			this.hyTbBeamBottomOffsetV.Text = Convert.ToDouble(streamReader.ReadLine()).ToString("f2");
			this.hyTbBeamTopOffsetV.Text = Convert.ToDouble(streamReader.ReadLine()).ToString("f2");
			this.hyTbBeamTopOffsetH.Text = Convert.ToDouble(streamReader.ReadLine()).ToString("f2");
			int num = Convert.ToInt32(streamReader.ReadLine());
			if (num == 0)
			{
				this.rbFirstFloor.Checked = true;
				this.rbMiddleFloor.Checked = false;
				this.rbTopFloor.Checked = false;
			}
			else if (1 == num)
			{
				this.rbFirstFloor.Checked = false;
				this.rbMiddleFloor.Checked = true;
				this.rbTopFloor.Checked = false;
			}
			else
			{
				this.rbFirstFloor.Checked = false;
				this.rbMiddleFloor.Checked = false;
				this.rbTopFloor.Checked = true;
			}
			this.hyTbRotateAngle.Text = YJKRevitStairs.StairsModel.CommonUnit.Common.StrToDouble(streamReader.ReadLine(), 0.0).ToString("f2");
			this.m_BasePointIndex = Convert.ToInt32(streamReader.ReadLine());
			this.chkTBMirror.Checked = Convert.ToBoolean(streamReader.ReadLine());
			this.chkLRMirror.Checked = Convert.ToBoolean(streamReader.ReadLine());
			this.chkNoteInfo.Checked = Convert.ToBoolean(streamReader.ReadLine());
			streamReader.Close();
			fileStream.Close();
		}

		public void SaveData()
		{
			FileStream fileStream = new FileStream(Path.GetTempPath() + "SteelStairsForm.dat", FileMode.Create);
			StreamWriter streamWriter = new StreamWriter(fileStream);
			streamWriter.WriteLine(this.cmbStairsType.SelectedIndex);
			streamWriter.WriteLine(this.hyTbStairsHeight.Text);
			streamWriter.WriteLine(this.hyTbStairsOffset.Text);
			streamWriter.WriteLine(this.cmbStairsAngle.Text);
			streamWriter.WriteLine(this.cmbStairsWidth.Text);
			streamWriter.WriteLine(this.tbStairsLength.Text);
			streamWriter.WriteLine(this.tbTreadCount.Text);
			streamWriter.WriteLine(this.hyTbTreadHeight.Text);
			streamWriter.WriteLine(this.tbTreadDepth.Text);
			streamWriter.WriteLine(this.chkInnerRailing.Checked);
			streamWriter.WriteLine(this.chkOutRailing.Checked);
			streamWriter.WriteLine(this.hyTbRailingHeight.Text);
			streamWriter.WriteLine(this.chkBottomBeam.Checked);
			streamWriter.WriteLine(this.chkTopBeam.Checked);
			streamWriter.WriteLine(this.cmbBeamType.SelectedIndex);
			streamWriter.WriteLine(this.hyTbBeamBottomOffsetV.Text);
			streamWriter.WriteLine(this.hyTbBeamTopOffsetV.Text);
			streamWriter.WriteLine(this.hyTbBeamTopOffsetH.Text);
			if (this.rbFirstFloor.Checked)
			{
				streamWriter.WriteLine(0);
			}
			else if (this.rbMiddleFloor.Checked)
			{
				streamWriter.WriteLine(1);
			}
			else
			{
				streamWriter.WriteLine(2);
			}
			streamWriter.WriteLine(this.hyTbRotateAngle.Text);
			streamWriter.WriteLine(this.m_BasePointIndex);
			streamWriter.WriteLine(this.chkTBMirror.Checked);
			streamWriter.WriteLine(this.chkLRMirror.Checked);
			streamWriter.WriteLine(this.chkNoteInfo.Checked);
			streamWriter.Flush();
			streamWriter.Close();
			fileStream.Close();
		}

		private void SteelStairsForm_Load(object sender, EventArgs e)
		{
			//base.Icon = Resource.YArchitechIcon;
			this.InitializeComboBox(this.cmbStairsType, this.m_slistStairsTypeName);
			this.InitializeComboBox(this.cmbBeamType, this.m_sListBeamTypeName);
			this.InitializeComboBox(this.cmbStairsAngle, this.GetStairsAngle());
			this.InitStairsWidth(this.GetStairsWidth());
			this.ReadData();
			this.UpdateBeamData();
			this.UpdateStairsData();
			this.UpdateRailingData();
			if (this.cmbStairsType.Text.Contains("斜钢梯"))
			{
				this.sLastStairsName = "斜钢梯";
				return;
			}
			this.sLastStairsName = "直梯";
		}

		private void SteelStairsForm_FormClosing(object sender, FormClosingEventArgs e)
		{
			if (DialogResult.Cancel == base.DialogResult)
			{
				return;
			}
			this.SaveData();
		}

		private void InitializeComboBox(System.Windows.Forms.ComboBox control, List<string> typeNameList)
		{
			control.Items.Clear();
			foreach (string item in typeNameList)
			{
				control.Items.Add(item);
			}
			if (control.Items.Count > 0)
			{
				control.SelectedIndex = 0;
			}
		}

		private void InitStairsWidth(List<string> typeNameList)
		{
			this.cmbStairsWidth.Items.Clear();
			foreach (string item in typeNameList)
			{
				this.cmbStairsWidth.Items.Add(item);
			}
		}

		private void SetComboBoxSelectedIndex(System.Windows.Forms.ComboBox control, int index)
		{
			if (index < 0 || index >= control.Items.Count)
			{
				return;
			}
			control.SelectedIndex = index;
		}

		private bool ValidatingParameters(ref string message)
		{
			double standardHeight = this.GetStandardHeight();
			if (0.0 < this.StairsHeight - standardHeight)
			{
				message = message + "您输入高度值超出《普通钢梯选用表6.1.6》中梯段极限高度值" + standardHeight.ToString() + "\n";
			}
			if (600.0 != this.StairsWidth && 700.0 != this.StairsWidth && 900.0 != this.StairsWidth && 1200.0 != this.StairsWidth)
			{
				message += "您输入宽度值超出《普通钢梯选用表6.1.6》中宽度极限\n";
			}
			return !("" != message);
		}

		private double GetStandardHeight()
		{
			double result = 0.0;
			double num = this.StairsAngle * 180.0 / Math.PI;
			string familyName = this.GetFamilyName();
			if (0.0 <= num - 90.0)
			{
				result = 4500.0;
			}
			else if (0.0 < num - 59.0 && 0.0 >= num - 73.0)
			{
				result = 4800.0;
			}
			else if (0.0 < num - 45.0 && 0.0 >= num - 59.0)
			{
				result = 5100.0;
			}
			else if (0.0 < num - 35.5 && 0.0 >= num - 45.0)
			{
				result = 4500.0;
			}
			else if (0.0 >= num - 35.5)
			{
				if (familyName.Contains("A") || familyName.Contains("B"))
				{
					result = 3600.0;
				}
				else
				{
					result = 3300.0;
				}
			}
			return result;
		}

		private void ParametersCalculate()
		{
			if ("" == this.hyTbStairsHeight.Text || "" == this.cmbStairsAngle.Text)
			{
				return;
			}
			if (!this.m_bRightAngle)
			{
				this.StairsLength = this.StairsHeight / Math.Tan(this.StairsAngle);
				this.TreadDepth = 600.0 / (2.0 * Math.Tan(this.StairsAngle) + 1.0);
				this.TreadHeight = this.TreadDepth * Math.Tan(this.StairsAngle);
				this.TreadCount = (int)(this.StairsHeight / this.TreadHeight - 1.0);
				return;
			}
			this.TreadCount = (int)(this.StairsHeight / this.TreadHeight);
		}

		private List<string> GetStairsTypeName(List<string> listStairsTypeName)
		{
			List<string> list = new List<string>();
			foreach (string text in listStairsTypeName)
			{
				if (text.Contains("90°直钢梯"))
				{
					if (!list.Contains("直梯"))
					{
						list.Add("直梯");
					}
				}
				else if (text.Contains("斜钢梯 A"))
				{
					if (!list.Contains("斜钢梯A"))
					{
						list.Add("斜钢梯A");
					}
				}
				else if (text.Contains("斜钢梯 B"))
				{
					if (!list.Contains("斜钢梯B"))
					{
						list.Add("斜钢梯B");
					}
				}
				else if (text.Contains("斜钢梯 C"))
				{
					if (!list.Contains("斜钢梯C"))
					{
						list.Add("斜钢梯C");
					}
				}
				else if (text.Contains("斜钢梯 D") && !list.Contains("斜钢梯D"))
				{
					list.Add("斜钢梯D");
				}
			}
			return list;
		}

		private List<string> GetStairsAngle()
		{
			List<string> list = new List<string>();
			if (this.m_bRightAngle)
			{
				list.Add("90");
			}
			else
			{
				list.Add("73");
				list.Add("59");
				list.Add("45");
				list.Add("35.5");
			}
			return list;
		}

		private List<string> GetStairsWidth()
		{
			return new List<string>
			{
				"600",
				"700",
				"900",
				"1200"
			};
		}

		private List<string> GetBeamTypeName(List<string> listBeamTypeName)
		{
			List<string> list = new List<string>();
			for (int i = 0; i < listBeamTypeName.Count; i++)
			{
				string text = listBeamTypeName.ElementAt(i);
				if (text.Contains("热轧槽钢"))
				{
					list.Add("C8");
					list.Add("C10");
					list.Add("C12");
					list.Add("C14");
					list.Add("C16");
					list.Add("C18");
					list.Add("C20");
					list.Add("C24");
				}
				else if (text.Contains("热轧H型钢"))
				{
					list.Add("HW150X150X7X10");
					list.Add("HW200X200X8X12");
					list.Add("HW300X300X10X15");
					list.Add("HW350X350X12X19");
					list.Add("HW400X400X13X21");
				}
			}
			return list;
		}

		private void UpdateRailingData()
		{
			if (!this.chkInnerRailing.Checked && !this.chkOutRailing.Checked)
			{
				this.hyTbRailingHeight.Enabled = false;
				return;
			}
			this.hyTbRailingHeight.Enabled = true;
		}

		private void UpdateBeamData()
		{
			if (!this.chkBottomBeam.Checked)
			{
				this.hyTbBeamBottomOffsetV.Enabled = false;
			}
			else
			{
				this.hyTbBeamBottomOffsetV.Enabled = true;
			}
			if (!this.chkTopBeam.Checked)
			{
				this.hyTbBeamTopOffsetV.Enabled = false;
				this.hyTbBeamTopOffsetH.Enabled = false;
			}
			else
			{
				this.hyTbBeamTopOffsetV.Enabled = true;
				this.hyTbBeamTopOffsetH.Enabled = true;
			}
			if (!this.chkBottomBeam.Checked && !this.chkTopBeam.Checked)
			{
				this.cmbBeamType.Enabled = false;
				return;
			}
			this.cmbBeamType.Enabled = true;
		}

		private void UpdateStairsData()
		{
			this.m_listStairsData.Clear();
			this.m_listStairsData.Add(this.StairsHeight);
			this.m_listStairsData.Add(this.StairsAngle);
			this.m_listStairsData.Add(this.StairsWidth);
			this.m_listStairsData.Add(this.TreadHeight);
			this.m_listStairsData.Add(this.RotateAngle);
			this.m_listStairsData.Add(this.RailingHeight);
			this.m_listStairsData.Add(this.BeamBottomOffsetV);
			this.m_listStairsData.Add(this.BeamTopOffsetV);
			this.m_listStairsData.Add(this.BeamTopOffsetH);
		}

		private void hyTbStairsHeight_TextChanged(object sender, EventArgs e)
		{
			this.ParametersCalculate();
			this.m_MainPreviewer.Refresh();
		}

		private void hyTbStairsOffset_TextChanged(object sender, EventArgs e)
		{
			this.m_MainPreviewer.Refresh();
		}

		private void hyTbBeamBottomOffsetV_TextChanged(object sender, EventArgs e)
		{
			this.m_MainPreviewer.Refresh();
		}

		private void hyTbBeamTopOffsetV_TextChanged(object sender, EventArgs e)
		{
			this.m_MainPreviewer.Refresh();
		}

		private void hyTbBeamTopOffsetH_TextChanged(object sender, EventArgs e)
		{
			this.m_MainPreviewer.Refresh();
		}

		private void hyTbRotateAngle_TextChanged(object sender, EventArgs e)
		{
			this.m_MainPreviewer.Refresh();
		}

		private void cmbStairsAngle_TextChanged(object sender, EventArgs e)
		{
			this.ParametersCalculate();
			this.m_MainPreviewer.Refresh();
		}

		private void cmbStairsWidth_TextChanged(object sender, EventArgs e)
		{
			this.m_MainPreviewer.Refresh();
		}

		private void hyTbTreadHeight_TextChanged(object sender, EventArgs e)
		{
			this.ParametersCalculate();
			this.m_MainPreviewer.Refresh();
		}

		private void hyTbRailingHeight_TextChanged(object sender, EventArgs e)
		{
			this.m_MainPreviewer.Refresh();
		}

		private void cmbStairsAngle_KeyPress(object sender, KeyPressEventArgs e)
		{
			string text = this.cmbStairsAngle.Text + e.KeyChar.ToString();
			e.Handled = (e.KeyChar < '0' || e.KeyChar > '9');
			if (e.KeyChar == '\b')
			{
				e.Handled = false;
			}
			if (e.KeyChar == '.')
			{
				if (text.Length <= 0)
				{
					e.Handled = true;
					return;
				}
				float num;
				if (float.TryParse(text, out num))
				{
					e.Handled = false;
				}
			}
		}

		private void cmbStairsWidth_KeyPress(object sender, KeyPressEventArgs e)
		{
			string text = this.cmbStairsWidth.Text + e.KeyChar.ToString();
			e.Handled = (e.KeyChar < '0' || e.KeyChar > '9');
			if (e.KeyChar == '\b')
			{
				e.Handled = false;
			}
			if (e.KeyChar == '.')
			{
				if (text.Length <= 0)
				{
					e.Handled = true;
					return;
				}
				float num;
				if (float.TryParse(text, out num))
				{
					e.Handled = false;
				}
			}
		}

		private void cmbStairsAngle_Validating(object sender, CancelEventArgs e)
		{
			string text = this.cmbStairsAngle.Text;
			if (text.Contains("."))
			{
				double num = 0.0;
				double.TryParse(text, out num);
				this.cmbStairsAngle.Text = num.ToString("f1");
			}
			else
			{
				int num2 = 0;
				int.TryParse(text, out num2);
				this.cmbStairsAngle.Text = num2.ToString();
			}
			double num3 = 0.0;
			if (!ValueValidatingKit.ValidatingDouble(this.cmbStairsAngle.Text, 35.5, 73.0, ref num3))
			{
				MessageBox.Show("钢梯角度参数不正确,允许输入范围(35.5°～73°).", "盈建科提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
				this.StairsAngle = this.m_listStairsData.ElementAt(1);
				e.Cancel = true;
				return;
			}
			this.UpdateStairsData();
			this.m_MainPreviewer.Refresh();
		}

		private void cmbStairsWidth_Validating(object sender, CancelEventArgs e)
		{
			string text = this.cmbStairsWidth.Text;
			if (text.Contains("."))
			{
				double num = 0.0;
				double.TryParse(text, out num);
				this.cmbStairsWidth.Text = num.ToString("f2");
			}
			else
			{
				int num2 = 0;
				int.TryParse(text, out num2);
				this.cmbStairsWidth.Text = num2.ToString();
			}
			double num3 = 0.0;
			if (!ValueValidatingKit.ValidatingDouble(this.cmbStairsWidth.Text, ValidatingType.GreaterThanZero, ref num3))
			{
				MessageBox.Show("梯段宽度参数不正确.", "盈建科提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
				this.StairsWidth = this.m_listStairsData.ElementAt(2);
				e.Cancel = true;
				return;
			}
			this.UpdateStairsData();
			this.m_MainPreviewer.Refresh();
		}

		private void hyTbStairsHeight_Validating(object sender, CancelEventArgs e)
		{
			if ("" == this.hyTbStairsHeight.Text)
			{
				return;
			}
			this.hyTbStairsHeight.Text = Convert.ToDouble(this.hyTbStairsHeight.Text).ToString("f2");
			double num = 0.0;
			if (!ValueValidatingKit.ValidatingDouble(this.hyTbStairsHeight.Text, ValidatingType.GreaterThanZero, ref num))
			{
				MessageBox.Show("钢梯高度参数不正确.", "盈建科提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
				this.StairsHeight = this.m_listStairsData.ElementAt(0);
				e.Cancel = true;
				return;
			}
			this.UpdateStairsData();
			this.m_MainPreviewer.Refresh();
		}

		private void hyTbStairsOffset_Validating(object sender, CancelEventArgs e)
		{
			if ("" == this.hyTbStairsOffset.Text)
			{
				return;
			}
			this.hyTbStairsOffset.Text = YJKRevitStairs.StairsModel.CommonUnit.Common.StrToDouble(this.hyTbStairsOffset.Text, 0.0).ToString("f2");
		}

		private void tbStairsLength_Validating(object sender, CancelEventArgs e)
		{
			if (this.m_bRightAngle)
			{
				this.tbStairsLength.Text = this.tbStairsLength.Text;
				return;
			}
			this.tbStairsLength.Text = Convert.ToDouble(this.tbStairsLength.Text).ToString("f2");
		}

		private void hyTbTreadHeight_Validating(object sender, CancelEventArgs e)
		{
			if ("" == this.hyTbTreadHeight.Text)
			{
				return;
			}
			this.hyTbTreadHeight.Text = Convert.ToDouble(this.hyTbTreadHeight.Text).ToString("f2");
			double num = 0.0;
			if (!ValueValidatingKit.ValidatingDouble(this.hyTbTreadHeight.Text, ValidatingType.GreaterThanZero, ref num))
			{
				MessageBox.Show("踏步高度参数不正确.", "盈建科提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
				this.TreadHeight = this.m_listStairsData.ElementAt(3);
				e.Cancel = true;
				return;
			}
			this.UpdateStairsData();
			this.m_MainPreviewer.Refresh();
		}

		private void tbTreadDepth_Validating(object sender, CancelEventArgs e)
		{
			if (this.m_bRightAngle)
			{
				this.tbTreadDepth.Text = this.tbTreadDepth.Text;
				return;
			}
			this.tbTreadDepth.Text = Convert.ToDouble(this.tbTreadDepth.Text).ToString("f2");
		}

		private void hyTbBeamBottomOffsetV_Validating(object sender, CancelEventArgs e)
		{
			if ("" == this.hyTbBeamBottomOffsetV.Text)
			{
				return;
			}
			this.hyTbBeamBottomOffsetV.Text = Convert.ToDouble(this.hyTbBeamBottomOffsetV.Text).ToString("f2");
			this.m_MainPreviewer.Refresh();
		}

		private void hyTbBeamTopOffsetV_Validating(object sender, CancelEventArgs e)
		{
			if ("" == this.hyTbBeamTopOffsetV.Text)
			{
				return;
			}
			this.hyTbBeamTopOffsetV.Text = Convert.ToDouble(this.hyTbBeamTopOffsetV.Text).ToString("f2");
			this.m_MainPreviewer.Refresh();
		}

		private void hyTbBeamTopOffsetH_Validating(object sender, CancelEventArgs e)
		{
			if ("" == this.hyTbBeamTopOffsetH.Text)
			{
				return;
			}
			this.hyTbBeamTopOffsetH.Text = Convert.ToDouble(this.hyTbBeamTopOffsetH.Text).ToString("f2");
			this.m_MainPreviewer.Refresh();
		}

		private void hyTbRotateAngle_Validating(object sender, CancelEventArgs e)
		{
			if ("" == this.hyTbRotateAngle.Text)
			{
				return;
			}
			this.hyTbRotateAngle.Text = YJKRevitStairs.StairsModel.CommonUnit.Common.StrToDouble(this.hyTbRotateAngle.Text, 0.0).ToString("f2");
			double num = 0.0;
			if (!ValueValidatingKit.ValidatingDouble(this.hyTbRotateAngle.Text, ValidatingType.Minus2PITo2PI, ref num))
			{
				MessageBox.Show("旋转角度参数不正确.", "盈建科提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
				e.Cancel = true;
				this.RotateAngle = this.m_listStairsData.ElementAt(4);
				return;
			}
			this.UpdateStairsData();
		}

		private void hyTbRailingHeight_Validating(object sender, CancelEventArgs e)
		{
			if ("" == this.hyTbRailingHeight.Text)
			{
				return;
			}
			this.hyTbRailingHeight.Text = Convert.ToDouble(this.hyTbRailingHeight.Text).ToString("f2");
			double num = 0.0;
			if (!ValueValidatingKit.ValidatingDouble(this.hyTbRailingHeight.Text, ValidatingType.GreaterThanZero, ref num))
			{
				MessageBox.Show("栏杆扶手高度参数不正确.", "盈建科提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
				this.RailingHeight = this.m_listStairsData.ElementAt(5);
				e.Cancel = true;
				return;
			}
			this.UpdateStairsData();
		}

		private void cmbStairsType_SelectedIndexChanged(object sender, EventArgs e)
		{
			if ("直梯" == this.cmbStairsType.Text)
			{
				this.m_bRightAngle = true;
			}
			else
			{
				this.m_bRightAngle = false;
			}
			if (!this.cmbStairsType.Text.Contains(this.sLastStairsName))
			{
				this.m_BasePointIndex = 0;
				this.InitializeComboBox(this.cmbStairsAngle, this.GetStairsAngle());
			}
			if (this.m_bRightAngle)
			{
				this.cmbStairsAngle.Enabled = false;
				this.lblStairsLength.Enabled = false;
				this.tbStairsLength.Text = "--";
				this.hyTbTreadHeight.ReadOnly = false;
				this.TreadHeight = 300.0;
				this.lblTreadDepth.Enabled = false;
				this.tbTreadDepth.Text = "--";
				this.rbFirstFloor.Enabled = false;
				this.rbFirstFloor.Checked = false;
				this.rbMiddleFloor.Enabled = false;
				this.rbMiddleFloor.Checked = false;
				this.rbTopFloor.Enabled = false;
				this.rbTopFloor.Checked = false;
				this.chkBottomBeam.Checked = false;
				this.chkBottomBeam.Enabled = false;
				this.lblBeamBottomOffsetV.Enabled = false;
				this.hyTbBeamBottomOffsetV.Enabled = false;
				this.chkNoteInfo.Checked = false;
				this.chkNoteInfo.Enabled = false;
			}
			else
			{
				this.cmbStairsAngle.Enabled = true;
				this.lblStairsLength.Enabled = true;
				this.hyTbTreadHeight.ReadOnly = true;
				this.lblTreadDepth.Enabled = true;
				this.rbFirstFloor.Enabled = true;
				this.rbFirstFloor.Checked = true;
				this.rbMiddleFloor.Enabled = true;
				this.rbTopFloor.Enabled = true;
				this.lblBeamBottomOffsetV.Enabled = true;
				this.chkBottomBeam.Enabled = true;
				this.hyTbBeamBottomOffsetV.Enabled = true;
				this.chkNoteInfo.Enabled = true;
				this.UpdateBeamData();
			}
			this.ParametersCalculate();
			if (this.cmbStairsType.Text.Contains("斜钢梯"))
			{
				this.sLastStairsName = "斜钢梯";
				return;
			}
			this.sLastStairsName = "直梯";
		}

		private void btnOk_Click(object sender, EventArgs e)
		{
			if (this.m_slistStairsTypeName.Count == 0)
			{
				YJKMessageBox.Show("钢梯类型为空", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
				return;
			}
			if (this.m_sListBeamTypeName.Count == 0)
			{
				YJKMessageBox.Show("梯梁类型为空", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
				return;
			}
			this.m_MeasureType = SteelStairsForm.MeasureType.MT_None;
			string message = "";
			if (!this.ValidatingParameters(ref message))
			{
				DialogResult dialogResult = YJKMessageBox.Show(message, MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
				if (DialogResult.Cancel == dialogResult)
				{
					return;
				}
				if (DialogResult.OK == dialogResult)
				{
					base.DialogResult = DialogResult.OK;
					base.Close();
				}
			}
			base.DialogResult = DialogResult.OK;
		}

		private void btnChangeInsertPoint_Click(object sender, EventArgs e)
		{
			int num = this.m_BasePointIndex + 1;
			if (this.m_bRightAngle)
			{
				this.m_BasePointIndex = num % 2;
			}
			else
			{
				this.m_BasePointIndex = num % 4;
			}
			this.m_MainPreviewer.Refresh();
		}

		private void btnStairsWidth_Click(object sender, EventArgs e)
		{
			this.m_MeasureType = SteelStairsForm.MeasureType.MT_StairsWidth;
			this.cmbStairsWidth.Focus();
		}

		private void btnRotateAngle_Click(object sender, EventArgs e)
		{
			this.m_MeasureType = SteelStairsForm.MeasureType.MT_Angle;
		}

		private void chkInnerRailing_CheckedChanged(object sender, EventArgs e)
		{
			this.UpdateRailingData();
			this.m_MainPreviewer.Refresh();
		}

		private void chkOutRailing_CheckedChanged(object sender, EventArgs e)
		{
			this.UpdateRailingData();
			this.m_MainPreviewer.Refresh();
		}

		private void chkBottomBeam_CheckedChanged(object sender, EventArgs e)
		{
			this.UpdateBeamData();
			this.m_MainPreviewer.Refresh();
		}

		private void chkTopBeam_CheckedChanged(object sender, EventArgs e)
		{
			this.UpdateBeamData();
			this.m_MainPreviewer.Refresh();
		}

		private void rbFirstFloor_CheckedChanged(object sender, EventArgs e)
		{
			this.m_MainPreviewer.Refresh();
		}

		private void rbMiddleFloor_CheckedChanged(object sender, EventArgs e)
		{
			this.m_MainPreviewer.Refresh();
		}

		private void rbTopFloor_CheckedChanged(object sender, EventArgs e)
		{
			this.m_MainPreviewer.Refresh();
		}

		private void chkNoteInfo_CheckedChanged(object sender, EventArgs e)
		{
			this.m_MainPreviewer.Refresh();
		}

		private void chkTBMirror_CheckedChanged(object sender, EventArgs e)
		{
			this.m_MainPreviewer.Refresh();
		}

		private void chkLRMirror_CheckedChanged(object sender, EventArgs e)
		{
			this.m_MainPreviewer.Refresh();
		}

		public const double _epsDouble = 1E-09;

		private List<string> m_slistStairsTypeName = new List<string>();

		public List<string> m_sListBeamTypeName = new List<string>();

		private ExternalCommandData m_Revit;

		private Previewer m_MainPreviewer;

		private SteelStairsKit m_StairsDrawingKit;

		private SteelStairsForm.MeasureType m_MeasureType;

		private XYZ m_BasePoint;

		private int m_BasePointIndex;

		private double m_dBottomElevation;

		private List<double> m_listStairsData;

		private bool m_bRightAngle;

		private string sLastStairsName = "";

		public enum MeasureType
		{
			MT_None,
			MT_StairsWidth,
			MT_Angle
		}
	}
}
